<?php

namespace think\wework\Api;

use think\wework\Abstracts\WeworkApiWithToken;

class Batch extends WeworkApiWithToken
{
    private static ?Batch $instance = null;
    public static function getInstance(): Batch
    {
        if(!self::$instance instanceof Batch) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * 邀请成员
     *
     * @param array $json
     * @return array
     */
    public function invite(array $json): array
    {
        return $this->httpClient->post('batch/invite', compact('json'))->toArray();
    }

    /**
     * 增量更新成员
     *
     * @param array $json
     * @return array
     */
    public function syncUser(array $json): array
    {
        return $this->httpClient->post('batch/syncuser', compact('json'))->toArray();
    }

    /**
     * 全量覆盖成员
     *
     * @param array $json
     * @return array
     */
    public function replaceUser(array $json): array
    {
        return $this->httpClient->post('batch/replaceuser', compact('json'))->toArray();
    }

    /**
     * 全量覆盖部门
     *
     * @param array $json
     * @return array
     */
    public function replaceParty(array $json): array
    {
        return $this->httpClient->post('batch/replaceparty', compact('json'))->toArray();
    }

    /**
     * 获取异步任务结果
     *
     * @param string $jobId
     * @return array
     */
    public function getResult(string $jobId): array
    {
        $query = ['jobid' => $jobId];
        return $this->httpClient->get('batch/getresult', compact('query'))->toArray();
    }
}
